<?php


/*
 CI Library Curl_post
 Written by: Ciprian Dimofte - 01-16-2010
 */
class Curl_post{
    
    public $CI;
    
    public function __construct(){
        $this->CI =& get_instance();
    }
    
    public function post($url, $postvars = array(), $return_transfer = 1){
        
        //Unserialize $postvars
        $post_request = "";
        foreach($postvars as $key => $value){
            $post_request .= $key . "=" . $value . "&";
        }
        $post_request .= "anti_cache=" . md5(mt_rand() . time() . microtime());
        
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_POST            ,1);
        curl_setopt($ch, CURLOPT_POSTFIELDS      ,$post_request);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION  ,1);
        curl_setopt($ch, CURLOPT_HEADER          ,0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER  , $return_transfer);
        $rec_data = curl_exec($ch);
        return $rec_data;
    }
    
    public function get($url, $postvars = array(), $return_transfer = 1){
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION  ,1);
        curl_setopt($ch, CURLOPT_HEADER          ,0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER  , $return_transfer);
        $rec_data = curl_exec($ch);
        return $rec_data;
    }
}

?>